import React, { Component } from 'react'
import { Button, Table, Modal, Row, Col, Popconfirm, Input, Form, message } from 'antd';
import { connect } from 'react-redux';
import { findAuditPass, passAudit, unpassAudit, getResourceInfo, getResourceTableInfo} from '../../../api/resourceCategory/resourceCategory'
import CommonView from '../commonView'
class PassedAudit extends Component {
  constructor() {
    super()
    this.state = {
      dataSource: [],
      showView: false,
      passDataSource: [],
      passBaseInfo: {},
      paginationNo: {
        pageSize: 10,
        defaultCurrent:1,
        current:1,
      },
      columns : [
        {
          title:'审核时间',key:'create_time',dataIndex:'create_time',
        },
        {
          title: '操作',dataIndex: 'action',key: 'action',width: 220,
          render: (text, record) => <Button size="small" type="link" onClick={() => this.handleView(record)}>查看</Button>
        }
      ]
    }


  }

  getPassed = (number, page, pageSize) => {
    findAuditPass({pageNum: page, pageSize: pageSize, number}).then(res => {
      if(res.data.metaData.code === 'success') {
        const paginationNo = this.state.paginationNo
        paginationNo.total = res.data.data.total
        paginationNo.current = res.data.data.pageNum
        this.setState({dataSource: res.data.data.list})
      }
    })
  }

  handleView = record => {
    let requestData = {resourceId: record.resource_id,}
    getResourceInfo(requestData).then(res => {
      if(res.data.metaData.code === 'success') {
        this.setState({passBaseInfo: res.data.data})
      }
    })
    getResourceTableInfo(requestData).then(res => {
      if(res.data.metaData.code === 'success') {
        this.setState({passDataSource: res.data.data, showView: true})
      }
    })
  }

  componentWillMount() {

      console.log('this.props.baseCOlumns', this.props.baseColumns)
      this.setState({
        columns: [...this.props.baseColumns ,...this.state.columns]
      })
      this.getPassed('01010101', 1,10)
    
  }
  showModal = () => {
    this.setState({
      show: true
    })
  }
  handleOk = e => {
    this.setState({
      show: false
    })
  }

  handleCancel = e => {
    this.setState({
      show: false
    })
  }

  //删除配置
  handleDeleteClick(code) {
    // this.props.deleteAnalyseTask({code: code})
  }
  render() {
    const  { curRecord, columns, dataSource, showView, passBaseInfo, passDataSource } = this.state
    return (
      <div>
          <Table
            size="small" loading={this.state.loading}
            dataSource={dataSource}
            columns={columns} bordered rowKey={record => record.taskId} 
            style={{ padding: 20 }}
            pagination={this.state.paginationNo} />
          
        <Modal title='查看'
         visible={showView} width={700}
         bodyStyle={{backgroundColor:'#f0f3f6',overflow:'auto',height:540}}
         onOk={this.handleOk} onCancel={e => this.setState({showView: false})} closable={true}
         footer={[<Button type="primary" size="small" onClick={e => this.setState({showView: false})}>确定</Button>]}
         >
           <CommonView dataSource={passDataSource} infos={passBaseInfo} />
        </Modal>
      </div>
    )
  }
}



const mapState = (state) => {
  // const { taskList} = state.DataAnalyseReducer;
  // const obj = {taskList}
  // console.log('质量剖析',obj)
  // return {
  //    taskList
  // }
}

const mapDispatch = (dispatch) => {
  return {
    deleteAnalyseTask(data) {
    },
    
  }
} 
export default connect(mapState, mapDispatch)(PassedAudit)


